package Scene4;

import Picture.GameImage;

import java.awt.image.BufferedImage;
import java.util.ArrayList;

public class Cow {
    int dir = 1;//1左2右
    public int x = 1200;
    public int y = 400;
    BufferedImage img;
    ArrayList<BufferedImage> arrayListRight = new ArrayList<>();
    ArrayList<BufferedImage> arrayListLeft = new ArrayList<>();
    int indexL = 0;
    int indexR = 0;
    double g = 20;
    double speed = 0;
    double t = 0.25;
    double s;
    int groundY = 650;
    public void jump(){

        double v0 = speed;
        s = v0*t - 0.5*g*t*t;
        double vt = v0 - g*t;
        speed = vt;
        y-=(int)s;
        if(y>=groundY)
            y = groundY;
    }
    public Cow() {
        img = GameImage.get("/Picture/cow/cl1.png");
        for (int i = 1; i < 5; i++) {
            arrayListLeft.add(GameImage.get("/Picture/cow/cl"+i+".png"));
        }
        for (int i = 1; i < 5; i++) {
            arrayListRight.add(GameImage.get("/Picture/cow/cr"+i+".png"));
        }
    }
    public void changeImage(){

        if(indexL==4){
            indexL = 0;
        }
        if(indexR==4){
            indexR = 0;
        }
        if(dir == 1){
            img = arrayListLeft.get(indexL);
            indexL++;
        }
        if(dir == 2){
            img = arrayListRight.get(indexR);
            indexR++;
        }
    }
}
